<%--<%@ page contentType="text/html;charset=UTF-8" %>--%>
<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<meta http-equiv="Content-Type"content="text/html;charset=UTF-8"/>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<style>
    .form-group {
        margin-top: 10px;
    }
    .staffApply{
        float:left;margin-left: 20px;
    }
</style>
<script>

    //手术间与手术室联动
    function changeOperatonRoom(){
        var roomId=$('#operatingRoomIdId').val();
        //alert(roomId);
        $('#operatingRoomNo option').remove();
        $('#operatingRoomNo').val('');
        $('#operatingRoomNo').html("<option value=''></option>");
        $.ajax({
            type: "POST",
            url: '${ctx}/operation/operationApply/findRoom?deptId='+roomId,
            dataType: "json",
            success: function (data) {
                console.log(data.dataMap);
                if(data.dataMap != null){
                    var html="";
                    for(var key in data.dataMap){
                        html+="<option value='"+key+"'>"+data.dataMap[key]+"</option>";
                    }
                    $('#operatingRoomNo').html(html);
                }
            },
            error: function (data) {
                toastr.error('网络连接错误,请检查网络');
            }
        });
    }
</script>
<script type="text/javascript">
    //手术项目动态行
    var idNum = 0;
    var id="operName"+idNum.toString();
    function addOperationApply() {
        //idNum = ${operationApply.operationNameApplys.size()} +1 - 1;
        var leftHtml = "";
        leftHtml += '<tr><input type="hidden" name="operationNameApplys[' + idNum + '].id"/><td><input data-parsley-required="true" id="operName'+idNum+'" name="operationNameApplys[' + idNum + '].operationName" class="form-control" cssStyle="border: none;margin:0;"/>' +
        '<input type="hidden" id="operCode'+idNum+'" name="operationNameApplys[' + idNum + '].operationCode"/><input type="hidden" id="operId'+idNum+'" name="operationNameApplys[' + idNum + '].operationId"/>'+
        <%--<c:forEach items="${operationDictList.list}" var="operationDict">
        '<option value="${operationDict.id}"  htmlEscape="false">${operationDict.operationName}</option>'+</c:forEach>--%>
        '</td><td class="col-sm-4"><select  style="width: 200px" data-parsley-required="true" id="operScale'+idNum+'" name="operationNameApplys[' + idNum + '].operationScale" class="form-control scale"><option value=""></option>' +
        <c:forEach items="${fns:getDictList('OPERATION_SCALE')}" var="type">
        '<option value="${type.value}">${type.label}</option>' +
        </c:forEach>
        '</select></td><td class="col-sm-2"><select id="operCrade'+idNum+'" name="operationNameApplys[' + idNum + '].woundGrade" data-parsley-required="true" class="form-control"><option value=""></option>' +
        <c:forEach items="${fns:getDictList('WOUND_GRADE_DICT')}" var="type">
        '<option value="${type.value}">${type.label}</option>' +
        </c:forEach>
        '</select></td>'
        leftHtml = leftHtml + '<td><button type="button" class="btn btn-danger" onclick="delOperationApply(this)">删除</button>' +
        '</td></tr>'
        $('#operationName').append(leftHtml);
        /*console.log(leftHtml);
        console.log("operScale"+idNum);
        console.log("operCrade"+idNum);*/
        //select2Load("operName");
        select2Load("operScale"+idNum);
        select2Load("operCrade"+idNum);
        id="operName"+idNum;
        autoCompleteDrugPrice(id,idNum);
        idNum = idNum + 1;
    }

    function delOperationApply(obj) {
        $(obj).parent().parent().remove();
    }

    function saveOperationApply() {
        if ($('#inputForm').parsley().validate()) {
            //console.log($("#inputForm").serialize());
            $.ajax({
                url: "${ctx}/operation/operationApply/save",
                type: "POST",
                dataType: "json",
                data: $('#inputForm').serialize(),
                success: function (data) {
                    if (data.code == "success") {
                        toastr.success('保存成功');
                        $("#contentDiv").load('${ctx}/operation/operationApply/applyList?clinicId=${clinicId}&patientId=${patientId}',function(){
                            hideShowTableTd('contentTable', '2,3,4,5', '1');
                        });
                        loadDiv('operationRigthCenterDiv','${ctx}/operation/operationApply/applyForm');
                        closeRight();
                        //hideShowTableTd('contentTable', '2,3,4', '1');
                        <%--$("#operationRigthCenterDiv").load('${ctx}/operation/operationApply/applyForm');--%>
                    }
                    else if(data.code == "no"){
                        toastr.error(data.data);
                    }
                    else {
                        toastr.error('保存失败');
                    }
                }
            })
        }
    }

    /*分配人员*/
    function assignButton(inputShow, inputHide) {
        var userIds = $("#" + inputHide).val();
        layerTree = layer.open({
            title: '分配人员',
            type: 2,
            area: ['500px', '520px'],
            fixed: false, //不固定
            maxmin: true,
            content: '${ctx}/sys/orgRole/usertorole?userId=' + userIds,
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                var resultIds = $(layero).find("iframe")[0].contentWindow.resultIds;
                var resultNames = $(layero).find("iframe")[0].contentWindow.resultNames;
                if((inputShow=='zdDoctorName'||inputShow=='myDoctorName'||inputShow=='kdDoctorNames') && resultNames.indexOf(",") > 0){
                    layer.alert('请勿选择多个医生',{
                        icon: 2,
                        skin: 'layer-ext-moon'
                    })
                }
                else{
                    console.log(inputShow+"+++++"+inputHide);
                    $("#" + inputShow).val(resultNames);
                    $("#" + inputHide).val(resultIds);
                    layer.close(index);
                }
            }, no: function (index) {
                layer.close(index);
            }
        });
    }


    function autoCompleteDrugPrice(inputId,idNum){
        var url="${ctx}/operation/operationApply/autoCompletePrice";
        autoComplete(inputId,url,
                function(data){
                    var rows = [];
                    for(var i=0; i<data.length; i++){
                        console.log(data);
                        rows[rows.length] = {
                            data:data[i],
                            value:data[i].id,
                            result:data[i].operName
                        };
                    }
                    return rows;
                },function(data, i, max){
                    return data.operName+"|"+"|"+ Math.round(parseFloat(data.operPrice)* 100)/100+"元";
                },function(event,data,formatted){
                    console.log(data);
                    $('#'+"operCode"+idNum).attr('value',data.operCode);
                    $('#'+"operId"+idNum).attr('value',data.id);
                });
    }
    //关闭右侧手术申请页面
    function closeRight(){
        $("#operationRigthCenterDiv").attr("style","display: none");
        $("#operationLeftDiv").attr("class","main-content col-lg-12");
        $("#operationLeftDiv").show('normal');
        hideShowTableTd('contentTable', '2,3,4,5', '1');
        $("#search").css("display","block");
    }


</script>

<section class="main-content col-lg-12" id="operationRigthCenterDiv">
    <div class="panel-body">
        <form:form id="inputForm" data-parsley-validate="" modelAttribute="operationApply"
                   method="post" class="form-horizontal">
            <form:hidden path="id"></form:hidden>
        <%--<input type="hidden" name="clinicId" value="${clinicId}"/>--%>
            <%--<input type="hidden" name="visitId" path="${operationApply.visitId}">--%>
       <%-- <input type="hidden" name="patientId" path="${operationApply.patientId}"/>--%>
            <form:hidden path="patientId" id="patientId" name="patientId" value="${operationApply.patientId}"></form:hidden>
            <form:hidden path="orgId"/>
        <div class="opertion_items">
            <div>手术项目</div>
        </div>
        <table class="table table-bordered table-striped mg-t datatable">
            <thead>
            <tr>
                <td>手术名称</td>
                <td>手术等级</td>
                <td>切口等级</td>
                <td>操作</td>
            </tr>
            </thead>
            <tbody id="operationName">
            <c:forEach items="${operationApply.operationNameApplys}" varStatus="operationName"
                       var="operationNameApply">
                <tr>
                    <td>
                        <form:hidden path="operationNameApplys[${operationName.index}].orgId"/>
                        <form:hidden path="operationNameApplys[${operationName.index}].id"></form:hidden>
                        <%--<form:input path="operationNameApplys[${operationName.index}].operationId"/>
                        <form:input path="operationNameApplys[${operationName.index}].operationCode"/>--%>
                        <form:input path="operationNameApplys[${operationName.index}].operationName" class="form-control" readonly="true" cssStyle="border: none;margin:0;"/>
                        <form:input path="operationNameApplys[${operationName.index}].operationId" class="form-control" type="hidden" cssStyle="border: none;margin:0;"/>
                        <%--<form:select data-parsley-validate="" path="operationNameApplys[${operationName.index}].operationId"
                                     class="form-control" data-parsley-required=""
                                     cssStyle="border: none;margin:0;">
                            <form:option value="" label="" selected="selected"/>
                            <c:forEach items="${operationDictList.list}" var="operationDict">
                                <form:option value="${operationDict.id}" htmlEscape="false">${operationDict.operationName}</form:option>
                            </c:forEach>
                        </form:select>--%>
                    </td>
                    <td class="col-sm-5">
                        <select name="operationNameApplys[${operationName.index}].operationScale"
                                class="form-control" style="width: 200px"  >
                            <option value="" label="" />
                            <c:forEach items="${fns:getDictList('OPERATION_SCALE')}" var="type">
                                <c:choose>
                                    <c:when test="${type.value==operationNameApply.operationScale}">
                                        <option value="${type.value}"
                                                selected="selected">${type.label}</option>
                                    </c:when>
                                    <c:otherwise>
                                        <option value="${type.value}">${type.label}</option>
                                    </c:otherwise>
                                </c:choose>

                            </c:forEach>
                        </select>
                    </td>
                    <td class="col-sm-2">
                        <select name="operationNameApplys[${operationName.index}].woundGrade"
                                class="form-control">
                            <option value="" label="" selected="selected"/>
                            <c:forEach items="${fns:getDictList('WOUND_GRADE_DICT')}" var="type">
                                <c:choose>
                                    <c:when test="${type.value==operationNameApply.woundGrade}">
                                        <option value="${type.value}"
                                                selected="selected">${type.label}</option>
                                    </c:when>
                                    <c:otherwise>
                                        <option value="${type.value}">${type.label}</option>
                                    </c:otherwise>
                                </c:choose>

                            </c:forEach>
                        </select>
                    </td>
                    <td>
                        <button type="button" class="btn btn-danger" onclick="delOperationApply(this)">删除</button>
                    </td>
                </tr>
            </c:forEach>

            </tbody>
        </table>
        <div class="button_position">
            <div class="pull-right">
                <button type="button" class="btn btn-primary" onclick="addOperationApply(this)">新增</button>
            </div>
        </div>

        <div class="opertion_items">
            <div>手术信息</div>
        </div>
        <fieldset>
            <legend><img src="${ctxStatic}/images/left.png" class="pull-left mt8">手术基本信息<img
                    src="${ctxStatic}/images/right.png" class="pull-right mt8"></legend>

            <div class="col-lg-12">

                <div class="form-group col-sm-12">
                    <label class="col-sm-2 control-label">术前诊断：</label>
                    <div class="col-sm-10">
                        <form:textarea path="diagBeforeOperation" data-parsley-required="true" value="${operationApply.diagBeforeOperation}" htmlEscape="false"
                                       maxlength="2000" class="form-control"/>
                    </div>
                </div>
                <div class="form-group col-sm-6">
                    <label class="col-sm-4 control-label">开单科室：</label>

                    <div class="col-sm-8">
                        <form:hidden path="visitId" id="visitId" name="visitId" value="${operationApply.visitId}"></form:hidden>
                        <form:hidden path="operationDeptId" id="orgDeptRightId" name="operationDeptId" value="${operationApply.operationDeptId}"></form:hidden>
                        <input  class="form-control" id="orgDeptName" value="${operationApply.operationName}" type="text" readonly="true"   />
                    <%--<sys:treeselect selectedParent="true" id="orgDeptRightId" name="operationDeptId" value="${operationApply.operationDeptId}"  update="${not empty orgDept.id}" labelName="${operationApply.operationName}" labelValue="${operationApply.operationName}"
                                        title="科室" url="/sys/orgDept/treeData" extId="${orgDept.id}" cssClass="form-control"/>--%>
                            <%--<sys:treeselect selectedParent="true" id="operatingRoomId" name="operatingRoomId" value="${operationApply.operatingRoomId}"  update="${not empty orgDept.id}" labelName="${operationApply.operatingRoomName}" labelValue="${operationApply.operatingRoomName}"--%>
                            <%--title="科室" url="/sys/orgDept/treeData" extId="${orgDept.id}" cssClass="form-control" isnull="true"/>--%>
                            <%--<form:select--%>
                            <%--path="operationDeptId"--%>
                            <%--class="form-control" data-parsley-required="true"--%>
                            <%--cssStyle="border: none;margin:0;">--%>
                            <%--<option value="" label=""/>--%>
                            <%--<c:forEach items="${orgDeptList.list}" var="orgDept">--%>
                            <%--<form:option value="${orgDept.id}" itemLabel="label" itemValue="value"--%>
                            <%--htmlEscape="false">--%>
                            <%--${orgDept.deptName}--%>
                            <%--</form:option>--%>
                            <%--</c:forEach>--%>
                            <%--</form:select>--%>
                    </div>
                </div>
                <div class="form-group col-sm-6">
                    <label class="col-sm-4 control-label">开单医生：</label>

                    <div class="col-sm-8">
                        <form:hidden path="doctorUser" id="kdDoctor" value="${operationApply.doctorUser}"></form:hidden>
                        <%--<input  class="form-control" id="kdDoctorNames" value="${operationApply.doctorName}" type="text" onclick="assignButton('kdDoctorNames','kdDoctor')" placeholder="分配人员"/>--%>
                        <input  class="form-control" id="kdDoctorNames" value="${operationApply.doctorName}" type="text" readonly="true"/>
                    </div>
                </div>
                <div class="form-group col-sm-6">
                    <label class="col-sm-4 control-label">预约时间：</label>

                    <div class="col-sm-8">
                        <input name="makeDate" htmlEscape="false" class="form-control Wdate"
                               data-parsley-required="true" readonly
                               onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"
                               value="<fmt:formatDate value="${operationApply.makeDate}" pattern="yyyy-MM-dd HH:mm:ss"/>" data-parsley-required="true"/>
                    </div>
                </div>

                <div class="form-group col-sm-6">
                    <label class="col-sm-4 control-label">手术时间：</label>

                    <div class="col-sm-8">
                        <fmt:formatDate value="${operationApply.scheduledDate}"
                                        pattern="yyyy-MM-dd HH:mm:ss" var="date"/>
                        <input name="scheduledDate" htmlEscape="false" class="form-control Wdate"
                               data-parsley-required="true" readonly
                               onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"
                               value="${date}"/>
                    </div>
                </div>
                <div class="form-group col-sm-6">
                    <label class="col-sm-4 control-label">手术室：</label>

                    <div class="col-sm-8">
                        <sys:treeselect method="changeOperatonRoom" selectedParent="true" id="operatingRoomId" name="operatingRoomId" value="${operationApply.operatingRoomId}"  update="${not empty orgDept.id}" labelName="${operationApply.operatingRoomName}" labelValue="${operationApply.operatingRoomName}"
                                        isnull="true"  title="科室" url="/sys/orgDept/treeData" extId="${orgDept.id}" cssClass="form-control"  />
                            <%--<form:select--%>
                            <%--path="operatingRoomId"--%>
                            <%--class="form-control" data-parsley-required="true"--%>
                            <%--cssStyle="border: none;margin:0;">--%>
                            <%--<option value="" label=""/>--%>
                            <%--<c:forEach items="${orgDeptList.list}" var="orgDept">--%>
                            <%--<form:option value="${orgDept.id}" itemLabel="label" itemValue="value"--%>
                            <%--htmlEscape="false">--%>
                            <%--${orgDept.deptName}--%>
                            <%--</form:option>--%>
                            <%--</c:forEach>--%>
                            <%--</form:select>--%>
                    </div>
                </div>
                <%--<div class="form-group col-sm-6">
                    <label class="col-sm-4 control-label">手术间：</label>
                    <div class="col-sm-8">
                        <form:select data-parsley-required=""
                                     path="operatingRoomNo" class="form-control">
                           &lt;%&ndash; &lt;%&ndash;<option value="" label=""/>&ndash;%&gt;
                            &lt;%&ndash;<c:forEach items="${operationRoomList.list}" var="operationRoom">&ndash;%&gt;
                            &lt;%&ndash;<form:option value="${operationRoom.id}" itemLabel="label"&ndash;%&gt;
                            &lt;%&ndash;itemValue="value" htmlEscape="false">&ndash;%&gt;
                            &lt;%&ndash;${operationRoom.roomNo}&ndash;%&gt;
                            &lt;%&ndash;</form:option>&ndash;%&gt;
                            &lt;%&ndash;</c:forEach>&ndash;%&gt;&ndash;%&gt;
                        </form:select>
                    </div>
                </div>--%>

                <div class="form-group col-sm-6">
                    <label class="col-sm-4 control-label">隔离等级：</label>

                    <div class="col-sm-8">

                        <form:select path="isolationIndicator" class="form-control"
                                     data-parsley-required="true" cssStyle="border: none;margin:0;">
                            <form:option value="" label=""/>
                            <form:options items="${fns:getDictList('QUARANTINE_MARK')}" itemLabel="label"
                                          itemValue="value" htmlEscape="false"/>
                        </form:select>
                    </div>
                </div>
                <input type="hidden" name="inoroutFlag" value="1"/>
                <%--<div class="form-group col-sm-6">
                    <label class="col-sm-4 control-label">输/供血方式：</label>

                    <div class="col-sm-8">
                        <form:select path="provideWay"
                                     class="form-control" data-parsley-required="true"
                                     cssStyle="border: none;margin:0;">
                            <form:option value="" label=""/>
                            <form:options items="${fns:getDictList('BLOOD_SUPPLY_WAY')}" itemLabel="label"
                                          itemValue="value" htmlEscape="false"/>
                        </form:select>
                    </div>
                </div>--%>
                <div class="form-group col-sm-6">
                    <label class="col-sm-4 control-label">病情：</label>

                    <div class="col-sm-8">
                        <form:select path="patientCondition"
                                     class="form-control" data-parsley-required="true"
                                     cssStyle="border: none;margin:0;">
                            <form:option value="" label=""/>
                            <form:options items="${fns:getDictList('PATIENT_CONDITION')}" itemLabel="label"
                                          itemValue="value" htmlEscape="false"/>
                        </form:select>
                    </div>
                </div>
                <%--<div class="form-group col-sm-6">
                    <label class="col-sm-4 control-label">麻醉方式：</label>

                    <div class="col-sm-8">
                        <form:select path="anesthesiaMethod"
                                     class="form-control" data-parsley-required="true"
                                     cssStyle="border: none;margin:0;">
                            <form:option value="" label=""/>
                            <form:options items="${fns:getDictList('ANESTHESIA_METHOD')}" itemLabel="label"
                                          itemValue="value" htmlEscape="false"/>
                        </form:select>
                    </div>
                </div>--%>
                <div class="form-group col-sm-6">
                    <label class="col-sm-4 control-label">是否急诊：</label>

                    <div class="col-sm-8">
                        <form:select path="emergencyFlag"
                                     class="form-control" data-parsley-required="true"
                                     cssStyle="border: none;margin:0;">
                            <form:option value="" label=""/>
                            <form:options items="${fns:getDictList('EMERGENCY_FLAG')}" itemLabel="label"
                                          itemValue="value" htmlEscape="false"/>
                        </form:select>
                    </div>
                </div>
            </div>
        </fieldset>
        <fieldset>
            <legend><img src="${ctxStatic}/images/left.png" class="pull-left mt8">手术人员信息<img
                    src="${ctxStatic}/images/right.png" class="pull-right mt8"></legend>
            <div class="col-sm-12">
                <div class="form-group col-sm-6">
                    <label class="col-sm-4 control-label">主刀医生：</label>

                    <div class="col-sm-8">
                        <form:hidden path="zdStaffApply.userId" id="zdDoctor"></form:hidden>
                        <input type="hidden" name="zdStaffApply.operationLocal" value="0"
                               class="form-control" id="zdDoctor"/>
                        <input  class="form-control"  data-parsley-required="true" id="zdDoctorName" value="${operationApply.zdStaffApply.userNames}"  type="text" onclick="assignButton('zdDoctorName','zdDoctor')" placeholder="分配人员" readonly="true"/>
                    </div>
                </div>
                <%--<div class="form-group col-sm-6">
                    <label class="col-sm-4 control-label">麻醉医生：</label>

                    <div class="col-sm-8">
                        <form:hidden path="myStaffApply.userId" id="myDoctor"></form:hidden>
                        <input name="myStaffApply.operationLocal" value="1"  class="form-control" type="hidden"/>
                        <input  class="form-control" id="myDoctorName" value="${operationApply.myStaffApply.userNames}"  type="text" onclick="assignButton('myDoctorName','myDoctor')" placeholder="分配人员"/>
                    </div>
                </div>
                <div class="form-group col-sm-6">
                    <label class="col-sm-4 control-label">输血医生：</label>

                    <div class="col-sm-8">
                        <form:hidden path="sxStaffApply.userIds" id="sxDoctor"></form:hidden>
                        <input name="sxStaffApply.operationLocal" value="2"  class="form-control" type="hidden"/>
                        <input  class="form-control" id="sxDoctorNames" value="${operationApply.sxStaffApply.userNames}" type="text" onclick="assignButton('sxDoctorNames','sxDoctor')" placeholder="分配人员"/>
                    </div>
                </div>

                <div class="form-group col-sm-6">
                    <label class="col-sm-4 control-label">麻醉助手：</label>

                    <div class="col-sm-8">
                        <form:hidden path="mzStaffApply.userIds" id="mzDoctor"></form:hidden>
                        <input name="mzStaffApply.operationLocal" value="3"  class="form-control" type="hidden"/>
                        <input  class="form-control" id="mzDoctorNames" value="${operationApply.mzStaffApply.userNames}" type="text" onclick="assignButton('mzDoctorNames','mzDoctor')" placeholder="分配人员"/>
                    </div>
                </div>--%>
                <div class="form-group col-sm-6">
                    <label class="col-sm-4">医生助手：</label>
                    <div class="col-sm-8">
                        <form:hidden path="yzStaffApply.userIds" id="yzDoctor"></form:hidden>
                        <input name="yzStaffApply.operationLocal" value="4"  class="form-control" type="hidden"/>
                        <input  class="form-control"  data-parsley-required="true" id="yzDoctorNames" value="${operationApply.yzStaffApply.userNames}" type="text" onclick="assignButton('yzDoctorNames','yzDoctor')" placeholder="分配人员" readonly="true"/>
                    </div>
                </div>
            </div>
        </fieldset>
        <div class="form-group">
            <div style="margin: 15px" class="pull-right">
                <input id="btnSubmit" class="btn btn-primary" type="button" value="保 存"
                       onclick="saveOperationApply()">&nbsp;
                <input id="btnCancel" class="btn" type="button" value="关 闭" onclick="closeRight()"></div>
            </div>
            </form:form>
        </div>

</section>


